package cn.sail.ssm.shop.exceptions.handler;


import cn.sail.ssm.shop.exceptions.BusinessException;
import cn.sail.ssm.shop.pojo.vo.ResultVO;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ShopExceptionHandler {

    @ResponseBody
    @ExceptionHandler(BusinessException.class)
    public ResultVO handlerBusinessExceptions(BusinessException e) {
        e.printStackTrace();
        ResultVO resultVO = new ResultVO();
        resultVO.setStatus(-1);
        resultVO.setMsg(e.getMessage());
        return resultVO;
    }

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public ResultVO handlerBusinessExceptions(Exception e) {
        e.printStackTrace();
        ResultVO resultVO = new ResultVO();
        resultVO.setStatus(-1);
        resultVO.setMsg(e.getMessage());
        return resultVO;
    }
}
